<template>
    <ListPage ref="page" :query="query" :api="getZzhFpgsList">

        <template #search="{ page, hiddenColumns }">
            <PageSearch ref="search" :query="query" :page="page" has-box @search="() => ($refs.page as any).getData()">
                <template #auth>
                </template>
                <template #input="{ }">
                    <SearchInput v-model="query.keyword" placeholder="客户名称/店铺名称/业务名称" :data="query"
                        :hidden-columns="(hiddenColumns as any)" @trigger="(e) => ($refs.search as any).trigger(e)"
                        @search="() => ($refs.page as any).getData()"
                        @change-column="(prop) => ($refs.page as any).changeColumn(prop)"></SearchInput>
                </template>
                <ElFormItem label="分配记录">
                    <ElSelect filterable clearable :="$attrs" placeholder="" v-model="query.fpjl">
                        <ElOption key="当前有效分配记录" label="当前有效分配记录" value="当前有效分配记录" />
                        <ElOption key="所有历史分配记录" label="所有历史分配记录" value="所有历史分配记录" />
                    </ElSelect>
                </ElFormItem>
            </PageSearch>
        </template>

        <template #table="{ data, hiddenColumns }">
            <ListTable :data="data" :hidden-columns="(hiddenColumns as any)" @openZzhFpgs="openZzhFpgs"
                @fpgsRevoke="fpgsRevoke">
            </ListTable>
        </template>

        <template #pagination="{ page, total }">
            <PagePagination :page="page" :total="total" @changePage="(v) => ($refs.page as any).changePage(v)">
            </PagePagination>
        </template>
    </ListPage>
</template>

<script setup lang="ts">
import ListPage from '@/components/list-page/ListPage.vue'
import PageSearch from '@/components/list-page/PageSearch.vue'
import SearchInput from '@/components/list-page/SearchInput.vue'
import ListTable from './ListTable.vue'
import { zzhFpGsDialog } from '../dialog/zzhFpgs'
import { ref, reactive } from 'vue'
import { getZzhFpgsList,postFpgsRevoke } from '../api'
import PagePagination from '@/components/list-page/PagePagination.vue'
import { ElMessageBox } from 'element-plus';


const page = ref()

const query = reactive({
    keyword: '',
    fpjl: '当前有效分配记录'
})

const openZzhFpgs = async (row) => {
    console.log(row);
    await zzhFpGsDialog.title('子账号分配公司').open(
        {
            row: {
                isAdd: true,
                customerShopBusinessId: row.customerShopBusinessId,
                zzhId: row.zzhId,
                jsrq: '2188-01-01',
                sqYwdx: row.sqYwdx,
                shYwdx: row.shYwdx,
                sfmsVal: row.sfmsVal,
                fpgsDx: row.shYwdx
            }
        }
    )
    page.value && page.value.getData();
}

const fpgsRevoke = async (row) => {
    console.log(row);
    await ElMessageBox.confirm('确定撤销吗？', '提示');
    await postFpgsRevoke(row);
    page.value && page.value.getData();
}
</script>